from tkinter import *


class BoardFrame():
    def __init__(self, root):
        super().__init__()
        self._frame = Frame(root)
        self.board = []
        self.createWidget()

    def getChar(self,row, clo):
        c='┼'
        if row==0:
            if clo==0:
                c='┏'
            elif clo==18:
                c='┓'
            else:
                c='┯'
        elif row==18:
            if clo==0:
                c='┗'
            elif clo==18:
                c='┛'
            else:
                c='┷'
        else:
            if clo==0:
                c='┠'
            elif clo==18:
                c='┨'
            else:
                c='┼'
        return c
    
    def reset(self):
        for row in range(19):
            for clo in range(19):
                self.board[row][clo].set(self.getChar(row, clo))

    def has_stone(self, row, clo):
        c=self.getChar(row, clo)
        return self.board[row][clo].get()!=c
        
    def play(self, row, clo, stone, isSet=True):
        c='┼'
        if stone.lower()=='b':
            c='●' if isSet else '◉' #a if a>b else b
        if stone.lower()=='w':
            c='◯' if isSet else '◎'
        self.board[row][clo].set(c)

    def setBoard(self, board):
        for y in range(19):
            for x in range(19):
                if board[y][x]==2:
                    self.board[y][x].set('●')
                elif board[y][x]==1:
                    self.board[y][x].set('◯')
                else:
                    self.board[y][x].set(self.getChar(y, x))
    def createWidget(self):
        for row in range(19):
            board_row = []
            for clo in range(19):
                c=self.getChar(row, clo)
                sVar = StringVar()
                sVar.set(c)
                lb=Label(self._frame,textvariable=sVar, font=("黑体", 12))
                lb.grid(row=row, column=clo, padx=0, pady=0, ipadx=0, ipady=0)
                board_row.append(sVar)
            self.board.append(board_row)
        for row in range(19):
            lb=Label(self._frame,text=str(row+1), font=("黑体", 12))
            lb.grid(row=row, column=19, padx=0, pady=0, ipadx=0, ipady=0)
        for col in range(19):
            lb=Label(self._frame,text='ABCDEFGHIJKLMNOPQRS'[col], font=("黑体", 12))
            lb.grid(row=19, column=col, padx=0, pady=0, ipadx=0, ipady=0)


if __name__ == '__main__':
    root=Tk()
    board=BoardFrame(root)
    board._frame.pack()
    board.play(3,3,'b')
    board.play(4,4,'w')
    root.mainloop()